package com.shms.action;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.shms.bean.GroupOfMessage;
import com.shms.constant.QueryConstant;
import com.shms.entity.ShMessage;
import com.shms.service.ShMessageService;

/**
 * 文件名：MessageAction.java
 * 编写者：杨勇
 * 创建时间：2013-4-12
 * 简要描述：
 * 
 */
public class MessageAction extends ActionSupport {
	
	private static final long serialVersionUID = 3769875698205425816L;
	private ShMessageService shMessageService;
	private GroupOfMessage groupOfMessage;
	private ShMessage shMessage;
	private String message;
	
	public String addMessage() {
		return SUCCESS;
	}
	
	/**
	 * 保存留言信息
	 * @return
	 */
	public String saveMessage() {
		boolean rtn = shMessageService.saveMessage(shMessage);
		if (rtn == false) {
			message = "保存失败";
		} else {
			message = "保存成功";
		}
		return SUCCESS;
	}
	
	/**
	 * 根据分页信息，查询留言信息列表
	 * @return 
	 */
	public String queryMessage() {
		//获取传来的当前页数
		Integer currentPage = Integer.parseInt(ServletActionContext.getRequest().getParameter("page"));
		//获取传来的上一页或下一页标志
		String type = ServletActionContext.getRequest().getParameter("param");
		//构造查询留言信息的分页信息输入参数
		GroupOfMessage groupOfMessageParams = new GroupOfMessage();
		groupOfMessageParams.setCurrentPage(currentPage);
		groupOfMessageParams.setType(type);
		groupOfMessageParams.setPageSize(QueryConstant.F_Pagesize);
		//查询
		groupOfMessage = shMessageService.queryMessage(groupOfMessageParams);
		if (groupOfMessage.getShMessage() == null)
			return INPUT;
		else 
			return SUCCESS;
	}
	
	public String queryMessageById() {
		//获取要查询的单条记录id
		long id = Long.parseLong(ServletActionContext.getRequest().getParameter("no"));
		ShMessage shMessageParams = new ShMessage();
		shMessageParams.setMid(id);
		shMessage = shMessageService.queryById(shMessageParams);
		return SUCCESS;
	}

	public ShMessageService getShMessageService() {
		return shMessageService;
	}

	public void setShMessageService(ShMessageService shMessageService) {
		this.shMessageService = shMessageService;
	}

	public GroupOfMessage getGroupOfMessage() {
		return groupOfMessage;
	}

	public void setGroupOfMessage(GroupOfMessage groupOfMessage) {
		this.groupOfMessage = groupOfMessage;
	}

	public ShMessage getShMessage() {
		return shMessage;
	}

	public void setShMessage(ShMessage shMessage) {
		this.shMessage = shMessage;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}
